#!/bin/bash
# 读取 MemTotal，单位 kB
mem_kb=$(grep -m1 '^MemTotal:' /proc/meminfo | awk '{print $2}')
# 转成 MB
mem=$(( mem_kb / 1024 / 1024))
echo $mem"GB"

if   [ "$mem" -le 2 ]; then
    swap=$(( mem * 2 ))
elif [ "$mem" -le 8 ]; then
    swap=$(( mem * 3 / 2 ))
else
    swap=8
fi

echo "推荐 swap 大小: ${swap}GB"